// pages/customer/customer.js
var app = getApp();
Page({
  data: {
    type: true,
    data: '',
    iconSize: 15,
    keyword: ''
  },
  onShow: function() {
    this.getCou();
  },
  getCou: function() {
    let that = this;
    let type = that.data.type ? '1' : '2';
    app.post('/shop/custManage', {
      type: type
    }).then(res => {
      that.setData({
        data: res,
      })
    });
  },
  switchType: function(e) {
    if (e.currentTarget.dataset.select == 'selected')
      return false;
    let that = this;
    this.setData({
      type: !that.data.type
    })
    this.getCou()
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    // 判断图标大小
    this.setData({
      iconSize: wx.getSystemInfoSync().windowWidth / 375 * 15
    })
  },
  inputSearch: function(e) {
    let keyword = e.detail.value;
    let that = this;
    let type = that.data.type ? '1' : '2';
    app.post('/shop/searchCustManage', {
      type: type,
      keyword: keyword
    }).then(res => {
      that.setData({
        data: res,
      })
    });
  },
  clearInputSearch: function(e) {
    this.setData({
      keyword: ''
    });
    this.getCou();
  },
  getdetail: function(e) {
    let id = e.currentTarget.dataset.id;
    let name = e.currentTarget.dataset.name;
    wx.navigateTo({
      url: './customer-detail/customer-detail?id=' + id + '&name=' + name,
    })
  },
  // onReachBottom: function() { //上拉加载
  //   wx.showLoading({
  //     title: '正在加载',
  //   })
  //   //加载次数加一
  //   this.setData({
  //     loadNumber: this.data.loadNumber + 1
  //   })
  //   if (this.data.loadNumber == 1) {
  //     this.setData({
  //       goodsList: this.data.goodsList.concat(this.data.goodsList1) //将返回的数据拼接到现有数据后面
  //     });
  //   } else if (this.data.loadNumber == 2) {
  //     this.setData({
  //       goodsList: this.data.goodsList.concat(this.data.goodsList2) //将返回的数据拼接到现有数据后面
  //     });
  //   }
  //   setTimeout(function() {
  //     wx.hideLoading()
  //   }, 1000)
  // }
})